package top.saplf.sileny.reader.shelf

import android.content.Intent
import com.chad.library.adapter.base.BaseItemDraggableAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jakewharton.rxbinding2.view.RxView
import kotlinx.android.synthetic.main.item_reader_index.view.*
import top.saplf.sileny.R

/**
 * @author Saplf on 17/4/19
 */
class LocalBookIndexAdapter(data: MutableList<LocalBook>) :
        BaseItemDraggableAdapter<LocalBook, BaseViewHolder>(R.layout.item_reader_index, data) {
    override fun convert(helper: BaseViewHolder, item: LocalBook) {
        with(helper) {
            with(item) {
                setText(R.id.bookName, item.name)
                RxView.clicks(itemView.bookView)
                        .subscribe {
                            mContext.startActivity(Intent(mContext, ReaderPageActivity::class.java).apply {
                                with(ReaderPageActivity) {
                                    bookId = item.id
                                }
                            })
                        }
            }
        }
    }
}